package com.lovo.emp.frame;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.lovo.common.model.EmpBean;
import com.lovo.emp.service.IEmpService;
import com.lovo.emp.service.impl.EmpServiceImpl;
import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoImageLabel;
import com.lovo.netCRM.component.LovoLabel;
import com.lovo.netCRM.component.LovoTitleLabel;


/**
 * 员工信息显示对话框
 * @author 白德柯
 *
 */
public class EmpShowDialog extends JDialog{

	/**姓名标签*/
	private LovoLabel nameLabel = new LovoLabel("姓    名",40,90,this);
	/**性别标签*/
	private LovoLabel genderLabel = new LovoLabel("性    别",300,90,this);
	/**登录名标签*/
	private LovoLabel loginNameLabel = new LovoLabel("登录名",40,130,this);
	/**文化程度标签*/
	private LovoLabel educationLabel = new LovoLabel("文化程度",300,130,this);
	/**出生日期标签*/
	private LovoLabel bornLabel = new LovoLabel("出生日期",40,170,this);
	/**联系方式标签*/
	private LovoLabel phoneLabel = new LovoLabel("联系方式",300,170,this);
	/**所属专业标签*/
	private LovoLabel subjectLabel = new LovoLabel("所属专业",40,210,this);
	/**政治面貌标签*/
	private LovoLabel politicalLabel = new LovoLabel("政治面貌",300,210,this);
	/**家庭地址标签*/
	private LovoLabel addrLabel = new LovoLabel("家庭地址",40,250,this);
	/**工作职位标签*/
	private LovoLabel workLabel = new LovoLabel("工作职位",300,250,this);
	/**所在部门标签*/
	private LovoLabel deptLabel = new LovoLabel("所在部门",40,290,this);
	/**入职时间标签*/
	private LovoLabel joinDateLabel = new LovoLabel("入职时间",300,290,this);
	/**头像标签*/
	private LovoImageLabel faceLabel = new LovoImageLabel(550, 90, 100, 100,this);

	private IEmpService empService = new EmpServiceImpl();
	/**员工Id*/
	private int id;


	public EmpShowDialog(JFrame jf,int id){
		super(jf,true);
		this.id = id;
		this.setLayout(null);
		this.init();
		this.setTitle("员工信息一览");
		Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
		int x = (int) screensize.getWidth() / 2 - 390;
		int y = (int) screensize.getHeight() / 2 - 225;
		this.setBounds(x,y,780, 450);
		this.setVisible(true);
	}
	/**
	 * 初始化
	 *
	 */
	private void init() {

		LovoTitleLabel titleLabel = new LovoTitleLabel("员工信息一览",this);
		titleLabel.setLocation(240, titleLabel.getY());
		this.initData(id);
		LovoButton cancelButton = new LovoButton(300,330,"确定","image/ok.png",this);
		cancelButton.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				EmpShowDialog.this.dispose();
			}});
	}
	
	//-------------------------
	/**
	 * 初始化数据
	 * @param id
	 */
	private void initData(int id){
		EmpBean empBean = empService.findById(id);
		nameLabel.setText(empBean.getName());
		genderLabel.setText(empBean.getGender());
		loginNameLabel.setText(empBean.getLoginName());
		educationLabel.setText(empBean.getEducation());
		if(empBean.getBorn() != null){
			bornLabel.setText(empBean.getBorn().toString());
		}
		phoneLabel.setText(empBean.getPhone());
		subjectLabel.setText(empBean.getSubject());
		politicalLabel.setText(empBean.getPolitical());
		addrLabel.setText(empBean.getAddr());
		workLabel.setText(empBean.getWorkName());
		deptLabel.setText(empBean.getDeptName());
		if(empBean.getJoinDate() != null){
			joinDateLabel.setText(empBean.getJoinDate().toString());
		}
		faceLabel.setImage(empBean.getFace());
	}


}
